package com.bs.message.service.impl;

import com.bs.ei.EIInfo;
import com.bs.message.service.RabbitmqService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author J
 */
@Service
public class RabbitmqServiceImpl implements RabbitmqService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    RabbitTemplate rabbitTemplate;
    @Autowired
    public RabbitmqServiceImpl(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @Override
    public EIInfo send(EIInfo eiInfo) {
        // 消息的一个唯一标识，当消息发送失败时，可以根据这个标识找回消息做后续处理
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend("topic.core","api", eiInfo, correlationData);
        return new EIInfo();
    }
}
